﻿using System;
using System.Data;
using System.Data.SqlClient;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class HRM_PRODUCT_GROUP
    {
        private bool m_Active;
        private string m_Description;
        private string m_ProductGroupCode;
        private string m_ProductGroupName;

        public HRM_PRODUCT_GROUP()
        {
            m_ProductGroupCode = "";
            m_ProductGroupName = "";
            m_Description = "";
            m_Active = true;
        }

        public HRM_PRODUCT_GROUP(string ProductGroupCode, string ProductGroupName, string Description, bool Active)
        {
            m_ProductGroupCode = ProductGroupCode;
            m_ProductGroupName = ProductGroupName;
            m_Description = Description;
            m_Active = Active;
        }

        public bool Active
        {
            get { return m_Active; }
            set { m_Active = value; }
        }

        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        public string ProductGroupCode
        {
            get { return m_ProductGroupCode; }
            set { m_ProductGroupCode = value; }
        }

        public string ProductGroupName
        {
            get { return m_ProductGroupName; }
            set { m_ProductGroupName = value; }
        }

        public string ProductName
        {
            get { return "Class HRM_PRODUCT_GROUP"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "ProductGroupName", "ProductGroupCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["ProductGroupCode"] = "All";
            row["ProductGroupName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "ProductGroupName", "ProductGroupCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["ProductGroupName"]);
            }
        }

        public string Delete()
        {
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {m_ProductGroupCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(string ProductGroupCode)
        {
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string ProductGroupCode)
        {
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string ProductGroupCode)
        {
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public bool Exist(string ProductGroupCode)
        {
            bool hasRows = false;
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string ProductGroupCode)
        {
            string str = "";
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_ProductGroupCode = Convert.ToString(reader["ProductGroupCode"]);
                    m_ProductGroupName = Convert.ToString(reader["ProductGroupName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string ProductGroupCode)
        {
            string str = "";
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "HRM_PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_ProductGroupCode = Convert.ToString(reader["ProductGroupCode"]);
                    m_ProductGroupName = Convert.ToString(reader["ProductGroupName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string ProductGroupCode)
        {
            string str = "";
            string[] myParams = {"@ProductGroupCode"};
            object[] myValues = {ProductGroupCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "HRM_PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_ProductGroupCode = Convert.ToString(reader["ProductGroupCode"]);
                    m_ProductGroupName = Convert.ToString(reader["ProductGroupName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PRODUCT_GROUP_GetList");
        }

        public string Insert()
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {m_ProductGroupCode, m_ProductGroupName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {m_ProductGroupCode, m_ProductGroupName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(string ProductGroupCode, string ProductGroupName, string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string ProductGroupCode, string ProductGroupName,
            string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string ProductGroupCode, string ProductGroupName,
            string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("HRM_PRODUCT_GROUP", "ProductGroupCode", "NH");
        }

        public string Update()
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {m_ProductGroupCode, m_ProductGroupName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(string ProductGroupCode, string ProductGroupName, string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string ProductGroupCode, string ProductGroupName,
            string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string ProductGroupCode, string ProductGroupName,
            string Description, bool Active)
        {
            string[] myParams = {"@ProductGroupCode", "@ProductGroupName", "@Description", "@Active"};
            object[] myValues = {ProductGroupCode, ProductGroupName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PRODUCT_GROUP_Update", myParams, myValues);
        }
    }
}